package com.archaeanx.libx

import com.archaeanx.libx.databinding.ItemBinding1Binding
import com.archaeanx.libx.databinding.ItemBinding2Binding
import com.archeanx.libx.adapter.binding.XRvBindingPureDataAdapter
import com.archeanx.libx.adapter.binding.XRvBindingHolder

class TestAdapter3 : XRvBindingPureDataAdapter<Int>() {

    val mItem1 = 11
    val mItem2 = 22

    override fun getItemViewBindingType(position: Int): Int {
        return if (getItem(position) % 2 == 0) {
            mItem1
        } else {
            mItem2
        }
        // return super.getItemViewBindingType(position)
    }


    override fun getBindingItemLayout(viewType: Int): Int {
        return when (viewType) {
            mItem1 -> R.layout.item_binding_1
            mItem2 -> R.layout.item_binding_2
            else -> R.layout.item_binding_1
        }
    }


    override fun onBindViewHolder(holder: XRvBindingHolder, position: Int, data: Int) {
        when (getItemViewBindingType(position)) {
            mItem1 -> {
                holder.getBinding<ItemBinding1Binding>().ibTxt1.text = data.toString()
            }
            mItem2 -> {
                holder.getBinding<ItemBinding2Binding>().dto = TestDto("item2:$data")
                holder.getBinding<ItemBinding2Binding>().itemB2.setBackgroundResource(R.color.colorAccent)
            }
        }

    }

    override fun onBindNoMoreDataViewHolder(holder: XRvBindingHolder, position: Int) {

    }

}